package com.nononsenseapps.feeder.net.obs

import android.content.Context
import com.gitee.wsl.android.ext.ApplicationInit
import com.gitee.wsl.jvm.net.server.DefaultHandler
import com.gitee.wsl.jvm.net.server.IStatus

import com.nononsenseapps.feeder.db.room.AppDatabase
import com.nononsenseapps.feeder.db.room.AppDatabase.Companion.getInstance
import com.nononsenseapps.feeder.db.room.FeedDao
import com.nononsenseapps.feeder.db.room.FeedItemDao

abstract class ObsAbstractHandler(context: Context= ApplicationInit.application) : DefaultHandler() {
    protected val database: AppDatabase
    protected val feedDao: FeedDao
    @JvmField
    protected val feedItemDao: FeedItemDao

    override var status: IStatus = ObsStatus.OK
    override var mimeType: String
        get() {
            if (status is ObsStatus) {
                val obsStatus = status as ObsStatus
                if (obsStatus.isJsonError) return "application/json"
                if (obsStatus != ObsStatus.OK) return "text/html"
            }
            return bodyMineType
        }
        set(value) {}


    abstract val bodyMineType: String

    init {
        database = getInstance(context)
        feedDao = database.feedDao()
        feedItemDao = database.feedItemDao()
    }

}
